﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IO = System.IO;
using System.Windows;
using System.Windows.Threading;
using System.Xml.Serialization;
using System.IO.Compression;
using System.Text.RegularExpressions;

namespace SLP
{
    public static class UIExtensions
    {
        /// <summary>
        /// Empty delegate for ForceRender and DoEvents
        /// </summary>
        private static System.Action EmptyDelegate = delegate () { };

        /// <summary>
        /// Replacement for WinForms DoEvents
        /// </summary>
        /// <param name="Source">Application</param>
        public static void DoEvents(this Application Source)
        {
            Source.Dispatcher.Invoke(DispatcherPriority.Background, EmptyDelegate);
        }

        /// <summary>
        /// Force a render even inside a loop        
        /// </summary>
        /// <param name="VisualElement"></param>
        public static void ForceRender(this System.Windows.UIElement VisualElement)
        {
            VisualElement.UpdateLayout();
            VisualElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
        }
    }
}
